home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Microsoft / Expression Blend / Blend.en.msi / Sparkle.CSwatch.Room.xaml.cs.en < prev    next >
Encoding:
Text File  |  2007-03-19  |  7.5 KB  |  103 lines

  1.  ■using System;
  2. using System.IO;
  3. using System.Net;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Data;
  7. using System.Windows.Media;
  8. using System.Windows.Media.Animation;
  9. using System.Windows.Navigation;
  10. using System.Diagnostics;
  11. namespace ColorSwatch
  12. {
  13.     /// <summary>
  14.     /// USER CONTROL:
  15.     /// Room is defined as a User Control to make it easier to send/receive events from Swatches and to the main window.
  16.     /// </summary>
  17.     public partial class Room
  18.     {
  19.         // Swatch selected
  20.         FrameworkElement currentSwatch;
  21.         /// <summary>
  22.         /// Exposes the method OnResetImage as a source to Data Binding in Expression Blend.
  23.         /// </summary>
  24.         public DelegateCommand ResetImage
  25.         {
  26.             get { return new DelegateCommand(delegate() { OnResetImage(); }); }
  27.         }
  28.         public Room()
  29.         {
  30.             this.InitializeComponent();
  31.             // Registers the events that can be accessed using Expression Blend, under Triggers in the Interaction panel.
  32.             EventManager.RegisterClassHandler(typeof(Swatch), Swatch.OpenSwatchEvent, new RoutedEventHandler(this.OnOpenSwatch));
  33.             EventManager.RegisterClassHandler(typeof(Swatch), Swatch.ColorSelectionChangedEvent, new RoutedEventHandler(this.OnColorSelectionChanged));
  34.         }
  35.         /// <summary>
  36.         /// The trigger for this method is defined inside the Swatch user control.
  37.         /// </summary>
  38.         public void OnOpenSwatch(object o, RoutedEventArgs e)
  39.         {
  40.             if (currentSwatch != null)
  41.             {
  42.                 Storyboard closeSwatchAnimation = (Storyboard)currentSwatch.FindResource("closeSwatch");
  43.                 closeSwatchAnimation.Begin(currentSwatch);
  44.             }
  45.             currentSwatch = (FrameworkElement)e.Source;
  46.             Storyboard closeOpenSwatchesAnimation = (Storyboard)this.Resources["closeAll"];
  47.             closeOpenSwatchesAnimation.Begin(this);
  48.             Storyboard openSwatchAnimation = (Storyboard)this.Resources["open" + currentSwatch.Name];
  49.             openSwatchAnimation.Begin(this);
  50.         }
  51.         private void OnResetImage()
  52.         {
  53.             WallBrush.Fill = Brushes.White;
  54.             FrameBrush.Fill = Brushes.White;
  55.             FloorBrush.Fill = Brushes.White;
  56.             BathtubBrush.Fill = Brushes.White;
  57.             TowelBrush.Fill = Brushes.White;
  58.         }
  59.         /// <summary>
  60.         /// Launches the browser from the application.
  61.         /// </summary>
  62.         private void OnLaunchBrowser(object sender, RoutedEventArgs e)
  63.         {
  64.             Process.Start("http://pro.corbis.com/");
  65.         }
  66.         private void OnColorSelectionChanged(object o, RoutedEventArgs e)
  67.         {
  68.             ColorSelectionEventArgs args = e as ColorSelectionEventArgs;
  69.             if (currentSwatch != null && args != null)
  70.             {
  71.                 Color newColor = (Color)ColorConverter.ConvertFromString(args.Color);
  72.                 SolidColorBrush newBrush = new SolidColorBrush(newColor);
  73.                 switch (currentSwatch.Name)
  74.                 {
  75.                     case "Wall":
  76.                         WallBrush.Fill = newBrush;
  77.                         break;
  78.                     case "Frame":
  79.                         FrameBrush.Fill = newBrush;
  80.                         break;
  81.                     case "Floor":
  82.                         FloorBrush.Fill = newBrush;
  83.                         break;
  84.                     case "Bathtub":
  85.                         BathtubBrush.Fill = newBrush;
  86.                         break;
  87.                     case "Towel":
  88.                         TowelBrush.Fill = newBrush;
  89.                         break;
  90.                 }
  91.             }
  92.         }
  93.     }
  94. }